package com.shell.arouter.ui.title

import android.graphics.Color
import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.StringRes
import com.durian.base.frame.activity.ActivityFrame
import com.durian.base.frame.titlebar.BaseSuperTitleBar
import com.durian.base.frame.viewbinding.viewBindings
import com.durian.base.utils.UIUtils
import com.henanjianye.soon.communityo2o2.R
import com.henanjianye.soon.communityo2o2.databinding.ActivityMainTitleBarBinding

/**
 * 说明：TitleBar
 * <p/>
 * 作者：Fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2020/04/07 11:57
 * <p/>
 * 版本：version 1.0
 */
class TitleBar(
        var titleBarText: String? = "",
        var isShowTitleBar : Boolean = false,
        var isShowTitleBarBack : Boolean = false,
        @StringRes var titleBarTextRes : Int = 0,
        @ColorRes var statusBar :  Int = R.color.base_app_theme_color,
        @ColorRes var navigationBar :  Int = R.color.base_white
) : BaseSuperTitleBar() {


    private val viewBinding by viewBindings<ActivityMainTitleBarBinding>()

    override fun bind(activity: ActivityFrame, view: View) {
        if (titleBarText?.isNotEmpty() == true){
            activity.title = titleBarText
        }
        if (titleBarTextRes > 0){
            activity.title = UIUtils.getString(titleBarTextRes)
        }
        viewBinding.toolbar.apply {
            immersionBar.statusBarView(viewBinding.viewEmpty)
                    .statusBarColor(statusBar)
                    .navigationBarColor(navigationBar)
                    .init()
            activity.setSupportActionBar(this)
            setTitleTextColor(Color.WHITE)
            if (isShowTitleBarBack){
                setNavigationIcon(R.drawable.ic_arrow_back_white_24dp)
                setNavigationOnClickListener {
                    activity.onBackPressed()
                }
            }
        }
    }

    override fun createTitleBar(activity: ActivityFrame): View? {
        return if (isShowTitleBar){
            viewBinding.root
        }else{
            null
        }
    }

}